package cn.ztq.test0614.ui.home;

import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.util.Log;

import androidx.annotation.NonNull;

import java.util.UUID;

public class GattCallBack  extends BluetoothGattCallback {
    final UUID BATTERY_SERVICE_UUID = UUID.fromString("0000180f-0000-1000-8000-00805f9b34fb");
    final UUID BATTERY_LEVEL_CHARACTERISTIC_UUID = UUID.fromString("00002a19-0000-1000-8000-00805f9b34fb");
    public GattCallBack() {
        super();
    }

    @Override
    public void onPhyUpdate(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
        super.onPhyUpdate(gatt, txPhy, rxPhy, status);
        Log.e("onPhyUpdate=====>","");
    }

    @Override
    public void onPhyRead(BluetoothGatt gatt, int txPhy, int rxPhy, int status) {
        super.onPhyRead(gatt, txPhy, rxPhy, status);
        Log.e("onPhyRead=====>","");
    }

    @Override
    public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
        super.onConnectionStateChange(gatt, status, newState);
//        BluetoothGattService batteryService = gatt.getService(BATTERY_SERVICE_UUID);
//        Log.e("batteryService====>",batteryService.toString());
//        BluetoothGattCharacteristic characteristic = batteryService.getCharacteristic(BATTERY_LEVEL_CHARACTERISTIC_UUID);
        BluetoothDevice device = gatt.getDevice();


        Log.e("status====>","name===>"+device.getName()+",status====>"+status+",newState====>"+newState);

    }

    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        super.onServicesDiscovered(gatt, status);
        Log.e("onServicesDiscovered=====>","");
    }

    @Override
    public void onCharacteristicRead(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value, int status) {
        super.onCharacteristicRead(gatt, characteristic, value, status);
        Integer intValue = characteristic.getIntValue(BluetoothGattCharacteristic.FORMAT_UINT8, 0);

        Log.e("onCharacteristicRead==========>", String.valueOf(intValue));

    }

    @Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
        super.onCharacteristicWrite(gatt, characteristic, status);
        Log.e("onCharacteristicWrite=====>","");
    }

    @Override
    public void onCharacteristicChanged(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattCharacteristic characteristic, @NonNull byte[] value) {
        super.onCharacteristicChanged(gatt, characteristic, value);
        Log.e("onCharacteristicChanged=====>","");
    }

    @Override
    public void onDescriptorRead(@NonNull BluetoothGatt gatt, @NonNull BluetoothGattDescriptor descriptor, int status, @NonNull byte[] value) {
        super.onDescriptorRead(gatt, descriptor, status, value);
        Log.e("onDescriptorRead=====>","");
    }

    @Override
    public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
        super.onDescriptorWrite(gatt, descriptor, status);
        Log.e("onDescriptorWrite=====>","");
    }

    @Override
    public void onReliableWriteCompleted(BluetoothGatt gatt, int status) {
        super.onReliableWriteCompleted(gatt, status);
        Log.e("onReliableWriteCompleted=====>","");
    }

    @Override
    public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
        super.onReadRemoteRssi(gatt, rssi, status);
        Log.e("onReadRemoteRssi=====>","");
    }

    @Override
    public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
        super.onMtuChanged(gatt, mtu, status);
        Log.e("onMtuChanged=====>","");
    }

    @Override
    public void onServiceChanged(@NonNull BluetoothGatt gatt) {
        super.onServiceChanged(gatt);
        Log.e("onServiceChanged=====>","");
    }
}
